package com.bc;

import java.io.File;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class BCImageAdapter extends BaseAdapter {


	private Context ctx;
	int imageBackground;
	String[] pics;


	public BCImageAdapter(Context c) {
	    ctx = c;
	    String [] listefichiers;
	    File repertoire = new File("/sdcard/myCards/");
		listefichiers=repertoire.list();
		pics = new String[listefichiers.length];
		
		int i;
		for(i=0;i<listefichiers.length;i++){
				pics[i] = "/sdcard/myCards/"+listefichiers[i];
		}
	}
	
	public BCImageAdapter(Context c, String directory) {
	    ctx = c;
	    String [] listefichiers;
	    File repertoire = new File(directory);
		listefichiers=repertoire.list();
		pics = new String[listefichiers.length];
		
		int i;
		for(i=0;i<listefichiers.length;i++){
				pics[i] = directory+listefichiers[i];
		}
	}


	public int getCount() {
	    return pics.length;
	}


	public Object getItem(int arg0) {
	    return arg0;
	}

	public long getItemId(int arg0) {
	    return arg0;
	}


	public View getView(int arg0, View arg1, ViewGroup arg2) {
	    ImageView iv = new ImageView(ctx);
	    Bitmap myBitmap1 = BitmapFactory.decodeFile(pics[arg0]);
	    iv.setImageBitmap(myBitmap1);
	    iv.setScaleType(ImageView.ScaleType.FIT_XY);
	    iv.setLayoutParams(new Gallery.LayoutParams(150,120));
	    iv.setBackgroundResource(imageBackground);
	    return iv;
	}
	
}